/**
 * 
 */
package com.hhuhh.smarthome.socket.support;

import java.nio.charset.Charset;

import org.apache.mina.filter.codec.textline.LineDelimiter;
import org.apache.mina.filter.codec.textline.TextLineCodecFactory;
import org.apache.mina.filter.executor.ExecutorFilter;
import org.apache.mina.filter.logging.LogLevel;
import org.apache.mina.filter.logging.LoggingFilter;

/**
 * @author John zhang
 * @version 0.1
 */
public class IoFilterHolder {
	
	private static TextLineCodecFactory textLineCodec;
	private static ByteCodecFactory byteCodec;
	private static LoggingFilter logFilter;
	
	public static TextLineCodecFactory textLineCodecFactory() {
		if( textLineCodec == null ) {
			textLineCodec = new TextLineCodecFactory ( Charset.forName ( "UTF-8" ), LineDelimiter.NUL, LineDelimiter.NUL );
			textLineCodec.setDecoderMaxLineLength ( 1024 * 1024 );
			textLineCodec.setEncoderMaxLineLength ( 1024 * 1024 );
		}
		return textLineCodec;
	}

	public static ExecutorFilter executorFilter( int poolSize ) {
		ExecutorFilter filter = new ExecutorFilter ( poolSize );
		return filter;
	}

	public static LoggingFilter loggingFilter() {
		if( logFilter == null ) {
			logFilter = new LoggingFilter ();
			logFilter.setMessageReceivedLogLevel ( LogLevel.DEBUG );
		}
		return logFilter;
	}
	
	public static ByteCodecFactory byteCodecFactory() {
		if( byteCodec == null ) {
			byteCodec = new ByteCodecFactory ();
		}
		return byteCodec;
	}
}
